/// 用户模型
class UserModel {
  final String id;
  final String account;
  final String password;
  final String username;
  final String signature;
  final String avatar;

  const UserModel({
    required this.id,
    required this.account,
    required this.password,
    required this.username,
    required this.signature,
    required this.avatar,
  });

  /// 从 JSON 创建用户模型
  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      id: json['id'] as String,
      account: json['account'] as String,
      password: json['password'] as String,
      username: json['username'] as String,
      signature: json['signature'] as String,
      avatar: json['avatar'] as String,
    );
  }

  /// 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'account': account,
      'password': password,
      'username': username,
      'signature': signature,
      'avatar': avatar,
    };
  }

  /// 复制用户模型并修改部分属性
  UserModel copyWith({
    String? id,
    String? account,
    String? password,
    String? username,
    String? signature,
    String? avatar,
  }) {
    return UserModel(
      id: id ?? this.id,
      account: account ?? this.account,
      password: password ?? this.password,
      username: username ?? this.username,
      signature: signature ?? this.signature,
      avatar: avatar ?? this.avatar,
    );
  }

  @override
  String toString() {
    return 'UserModel(id: $id, account: $account, username: $username)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is UserModel && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;
}
